home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Business & Presentations
/
Business and Presentations - Volume 1 (1995)(Sideface)(NL).iso
/
drivers
/
dvips54
/
dopage.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-11-25
|
11KB
|
348 lines
/*
* Main page drawing procedure. Interprets the page commands. A simple
* (if lengthy) case statement interpreter.
*/
#include "structures.h" /* The copyright notice in that file is included too! */
#include <math.h>
/*
* The external routines we use:
*/
extern void error() ;
extern void pageinit() ;
extern void drawrule() ;
extern shalfword dvibyte() ;
extern halfword twobytes() ;
extern integer threebytes() ;
extern integer signedquad() ;
extern shalfword signedbyte() ;
extern shalfword signedpair() ;
extern integer signedtrio() ;
extern void dospecial() ;
extern void drawchar() ;
extern integer scalewidth() ;
extern void skipover() ;
#ifndef XENIX
extern double floor() ;
#endif
extern void fontdef() ;
extern void pageend() ;
/*
* Now the external variables.
*/
extern fontdesctype *curfnt ;
extern fontdesctype *baseFonts[] ;
extern fontmaptype *ffont ;
extern quarterword *curpos, *curlim ;
extern integer hh, vv ;
/*
* CONVENTION: conv -> horizontial converter
* vconv -> vertical converter
*/
extern real conv ;
extern real vconv ;
extern FILE *bitfile ;
extern int actualdpi ;
extern int vactualdpi ;
extern frametype frames[] ;
extern int maxdrift ;
extern int vmaxdrift ;
#ifdef EMTEX
extern void emclear() ;
#endif
#ifdef XENIX
#define PixRound(x) ((integer)(x + (iconv >> 1)) / iconv)
#define VPixRound(x) ((integer)(x + (viconv >> 1)) / viconv)
#else
#define PixRound(x) (floor(((x) * conv) + 0.5))
#define VPixRound(x) (floor(((x) * vconv) + 0.5))
#endif
/*
* Now we have the dopage procedure.
* Most error checking is suppressed because the prescan has already
* verified that the DVI data is OK....except for stack over/underflow.
*/
static struct dvistack {
integer hh, vv ;
integer h, v, w, x, y, z ;
} stack[STACKSIZE] ;
void
dopage()
{
register shalfword cmd ;
register integer p ;
register chardesctype *cd ;
register integer h ;
register fontmaptype *cfnt ;
register frametype *frp = frames ;
integer fnt ;
int charmove ;
struct dvistack *sp = stack ;
integer v, w, x, y, z ;
integer roundpos ;
integer thinspace ;
integer vertsmallspace ;
#ifdef XENIX
integer iconv ;
integer viconv ;
iconv = (integer)(1.0 / conv + 0.5) ;
viconv = (integer)(1.0 / vconv + 0.5) ;
#endif
#ifdef EMTEX
emclear() ;
#endif
pageinit() ;
thinspace = (integer)(0.025*DPI/conv) ; /* 0.025 inches */
vertsmallspace = (integer)(0.025*VDPI/vconv) ; /* 0.025 inches */
hh = vv = h = v = w = x = y = z = 0 ;
curfnt = NULL ;
curpos = NULL ;
charmove = 0 ;
beginloop:
switch (cmd=dvibyte()) {
case 138: goto beginloop ; /* nop command does nuttin */
/*
* For put1 commands, we subtract the width of the character before
* dropping through to the normal character setting routines. This
*/
case 133: /* put1 */
cmd = dvibyte() ;
charmove = 0 ;
goto dochar ;
case 128: cmd = dvibyte() ; /* set1 command drops through to setchar */
default: /* these are commands 0 (setchar0) thru 127 (setchar127) */
charmove = 1 ;
dochar:
cd = &(curfnt->chardesc[cmd]) ;
if (cd->flags & EXISTS) {
if (curfnt->loaded == 2) { /* virtual character being typeset */
if (charmove) {
sp->hh = hh + cd->pixelwidth ; sp->vv = vv ;
sp->h = h + cd->TFMwidth ; sp-> v = v ;
} else {
sp->hh = hh ; sp->h = h ;
}
sp->vv = vv ; sp-> v = v ;
sp->w = w ; sp->x = x ; sp->y = y ; sp->z = z ;
if (++sp >= &stack[STACKSIZE]) error("! Out of stack space") ;
w = x = y = z = 0 ; /* will be in relative units at new stack level */
frp->curp = curpos ;
frp->curl = curlim ;
frp->ff = ffont ;
frp->curf = curfnt ;
if (++frp == &frames[MAXFRAME] )
error("! virtual recursion stack overflow") ;
cd = curfnt->chardesc + cmd ;
curpos = cd->packptr + 2 ;
curlim = curpos + (256*(long)(*cd->packptr)+(*(cd->packptr+1))) ;
ffont = curfnt->localfonts ;
if (ffont) {
curfnt = ffont->desc ;
thinspace = curfnt->thinspace ;
} else {
curfnt = NULL ;
thinspace = vertsmallspace ;
}
goto beginloop ;
}
drawchar(cd, cmd) ;
}
if (charmove) {
h += cd->TFMwidth ;
hh += cd->pixelwidth ;
}
goto setmotion ;
case 129: case 130: case 131: case 134: case 135: case 136: case 139:
case 247: case 248: case 249: case 250: case 251: case 252: case 253:
case 254: case 255: /* unimplemented or illegal commands */
error("! synch") ;
case 132: case 137: /* rules */
{ integer ry, rx , rxx, ryy ;
ry = signedquad() ; rx = signedquad() ;
if (rx>0 && ry>0) {
if (curpos) {
rx = scalewidth(rx, (frp-1)->curf->scaledsize) ;
ry = scalewidth(ry, (frp-1)->curf->scaledsize) ;
}
rxx = (conv * rx + 0.9999999) ;
ryy = (vconv * ry + 0.9999999) ;
drawrule(rxx, ryy) ;
} else
rxx = 0 ;
if (cmd == 137) goto beginloop ;
h += rx ; hh += rxx ;
goto setmotion ;
}
case 141: /* push */
sp->hh = hh ; sp->vv = vv ; sp->h = h ; sp->v = v ;
sp->w = w ; sp->x = x ; sp->y = y ; sp->z = z ;
if (++sp >= &stack[STACKSIZE]) error("! Out of stack space") ;
goto beginloop ;
case 140: /* eop or end of virtual character */
if (curpos == NULL) break ; /* eop */
--frp ;
curfnt = frp->curf ;
thinspace = (curfnt) ? curfnt->thinspace : vertsmallspace ;
ffont = frp->ff ;
curlim = frp->curl ;
curpos = frp->curp ;
if (hh < (sp-1)->hh+2 && hh > (sp-1)->hh-2)
(sp-1)->hh = hh; /* retain `intelligence' of pixel width, if close */
/* falls through */
case 142: /* pop */
if (--sp < stack) error("! More pops than pushes") ;
hh = sp->hh ; vv = sp->vv ; h = sp->h ; v = sp->v ;
w = sp->w ; x = sp->x ; y = sp->y ; z = sp->z ;
goto beginloop ;
case 143: /* right1 */
p = signedbyte() ; goto horizontalmotion ;
case 144: /* right2 */
p = signedpair() ; goto horizontalmotion ;
case 145: /* right3 */
p = signedtrio() ; goto horizontalmotion ;
case 146: /* right4 */
p = signedquad() ; goto horizontalmotion ;
case 147: /* w0 */
p = w ; goto horizontalmotion ;
case 148: /* w1 */
p = w = signedbyte() ; goto horizontalmotion ;
case 149: /* w2 */
p = w = signedpair() ; goto horizontalmotion ;
case 150: /* w3 */
p = w = signedtrio() ; goto horizontalmotion ;
case 151: /* w4 */
p = w = signedquad() ; goto horizontalmotion ;
case 152: /* x0 */
p = x ; goto horizontalmotion ;
case 153: /* x1 */
p = x = signedbyte() ; goto horizontalmotion ;
case 154: /* x2 */
p = x = signedpair() ; goto horizontalmotion ;
case 155: /* x3 */
p = x = signedtrio() ; goto horizontalmotion ;
case 156: /* x4 */
p = x = signedquad() ; goto horizontalmotion ;
case 157: /* down1 */
p = signedbyte() ; goto verticalmotion ;
case 158: /* down2 */
p = signedpair() ; goto verticalmotion ;
case 159: /* down3 */
p = signedtrio() ; goto verticalmotion ;
case 160: /* down4 */
p = signedquad() ; goto verticalmotion ;
case 161: /* y0 */
p = y ; goto verticalmotion ;
case 162: /* y1 */
p = y = signedbyte() ; goto verticalmotion ;
case 163: /* y2 */
p = y = signedpair() ; goto verticalmotion ;
case 164: /* y3 */
p = y = signedtrio() ; goto verticalmotion ;
case 165: /* y4 */
p = y = signedquad() ; goto verticalmotion ;
case 166: /* z0 */
p = z ; goto verticalmotion ;
case 167: /* z1 */
p = z = signedbyte() ; goto verticalmotion ;
case 168: /* z2 */
p = z = signedpair() ; goto verticalmotion ;
case 169: /* z3 */
p = z = signedtrio() ; goto verticalmotion ;
case 170: /* z4 */
p = z = signedquad() ; goto verticalmotion ;
case 171: case 172: case 173: case 174: case 175: case 176: case 177:
case 178: case 179: case 180: case 181: case 182: case 183: case 184:
case 185: c